import BaseController from '../../core/controllers/Base.controller';
import storageApi from '../../core/storage/storage';

@Inject('$log', '$rootScope', 'globalService', 'deviceService', 'ngDialog', 'ngDialogService')
class DeviceCheckController extends BaseController {
  constructor() {
    super(deviceService, 'queryCheck');

    this.paginationService = this.deviceService;
    this.$setQueryCallback((res) => {
      this.equipCheckData = res.rows;
    });

    this.mapParams = {
      orgId: $rootScope.orgId || storageApi.get('orgId'),
    };
    this.$paginationQuery();
  }

  $query(param) {
    if (param && param.checkTimeMin.$valid && param.checkTimeMax.$valid
      && param.checkTimeMin.$viewValue > param.checkTimeMax.$viewValue) {
      this.ngDialogService.alertError('下次检测时间应大于检测时间');
      return;
    }
    this.$paginationQuery();
  }

  $reset() {
    this.mapParams = {
      orgId: this.$rootScope.orgId || storageApi.get('orgId'),
    };
  }
}

export default DeviceCheckController;
